package com.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.android.ocean.util.common.StringUtil;
import com.app.DemoApplication;
import com.modle.User;

public class SpUserUtil {
	// 用户数据
	public static String USER_INFO = "USER_INFO";


	/**
	 * 
	 * @Description:TODO保存用户信息
	 * @param u
	 * @return void
	 * @author zhuw
	 * @date 2013-4-25 下午5:07:50
	 */
	public static void saveUser(User u) {
		try {
			SharedPreferences.Editor editor = DemoApplication.mContext
					.getSharedPreferences(USER_INFO, Context.MODE_PRIVATE)
					.edit();
			editor.putString("userID", u.id);
			editor.putString("nickName", u.nickName);
			editor.putString("iyrNum", u.iyrNum);
			editor.putString("mobile", u.mobile);
			editor.putString("firstWord", u.firstWord);
			editor.putString("type", u.type);
			editor.putBoolean("isMember", u.isMember);
			editor.putString("thumb", u.thumb);
			editor.putString("male", u.male);
			editor.putString("signature", u.signature);
			editor.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 
	 * @Description:TODO读取用户信息
	 * @return
	 * @return User
	 * @author zhuw
	 * @date 2013-4-25 下午5:08:08
	 */
	public static User readUser() {
		User u = null;
		try {
			SharedPreferences sp = DemoApplication.mContext
					.getSharedPreferences(USER_INFO, Context.MODE_PRIVATE);
			//判断是否存在用户
			if (sp != null&&!StringUtil.isNull(sp.getString("userID", ""))) {
				
				u = new User();
				u.id = sp.getString("userID", "");
				u.nickName = sp.getString("nickName", "");
				u.iyrNum = sp.getString("email", "");
				u.mobile = sp.getString("mobile", "");
				u.firstWord = sp.getString("firstWord", "");
				u.type = sp.getString("type", "");
				u.thumb = sp.getString("thumb", "");
				u.male = sp.getString("male", "");
				u.signature = sp.getString("signature", "");
				u.isMember = sp.getBoolean("isMember", false);

			}
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		return u;
	}
	/**
	 * 
	 * @Description:TODO清空用户信息
	 * @return void
	 * @author zhuw
	 * @date 2013-4-25 下午5:08:20
	 */
	public static void clearUser() {
		try {
			SharedPreferences.Editor editor = DemoApplication.mContext
					.getSharedPreferences(USER_INFO, Context.MODE_PRIVATE)
					.edit();
			editor.clear();
			editor.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
